import type { NextConfig } from 'next';

const checkEnv = (name: string, defaultVal?: string) => {
  const val = process.env[name] ?? defaultVal;
  if (!val) {
    console.error(`env ${name} not existed`);
    process.exit(1);
  }
  return val;
};

const nextConfig: NextConfig = {
  output: 'standalone',
  serverExternalPackages: ['@node-rs/jieba'],
  images: {
    remotePatterns: [
      {
        protocol: 'https',
        hostname: 'rin-takeout-dev-1322157999.cos.ap-guangzhou.myqcloud.com',
        port: '',
        pathname: '/**',
      },
    ],
  },
  async rewrites() {
    return [
      {
        source: '/socket.io/:path*',
        destination: `${checkEnv('SOCKET_URL')}/socket.io/:path*`,
      },
    ];
  },
};

export default nextConfig;
